#include "vector4.h"
#include <cmath>
namespace RayTrace{
vector4::vector4(void)
{
}

vector4::~vector4(void)
{
}
vector4::vector4(float _x,float _y,float _z,float _w)
{
	x=_x;
	y=_y;
	z=_z;
	w=_w;
}
vector4 vector4::operator /( float b) const
{
	vector4 ans;
	ans.x=this->x/b;
	ans.y=this->y/b;
	ans.z=this->z/b;
	ans.w=this->w/b;
	return ans;
}
vector4 vector4::operator *( float b) const
{
	vector4 ans;
	ans.x=this->x*b;
	ans.y=this->y*b;
	ans.z=this->z*b;
	ans.w=this->w*b;
	return ans;
}
vector4 vector4::operator *(const vector4 &b) const
{
	vector4 ans;
	ans.x=this->x*b.x;
	ans.y=this->y*b.y;
	ans.z=this->z*b.z;
	ans.w=this->w*b.w;
	return ans;
}
vector4 vector4::operator +(const vector4 &b) const
{
	vector4 ans;
	ans.x=this->x+b.x;
	ans.y=this->y+b.y;
	ans.z=this->z+b.z;
	ans.w=this->w+b.w;
	return ans;
}
vector4 vector4::operator -(const vector4 &b) const
{
	vector4 ans;
	ans.x=this->x-b.x;
	ans.y=this->y-b.y;
	ans.z=this->z-b.z;
	ans.w=this->w-b.w;
	return ans;
}
vector4 vector4::Normalize()
{
	vector4 ans;
	vector4 b=*this;
	float d=sqrt(b.x*b.x+b.y*b.y+b.z*b.z+b.w*b.w);
	ans.x=b.x/d;
	ans.y=b.y/d;
	ans.z=b.z/d;
	ans.w=b.w/d;
	return ans;
}
float vector4::Dot(const vector4 &a,const vector4 &b)
{
	return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w;
}

vector4 vector4::LimitInColorRange(const vector4 &a)
{
	vector4 ans=a;
	if (ans.x>1.0f) ans.x=1.0f;
	if (ans.y>1.0f) ans.y=1.0f;
	if (ans.z>1.0f) ans.z=1.0f;
	if (ans.w>1.0f) ans.w=1.0f;
	return ans;
}

vector4 operator *(float b,const vector4& a)  
{
	return  a.operator *(b);
}
}